package server;

import java.nio.channels.SelectionKey;

import tool.ExecutorServiceTool;

public class GpcRequestObserver implements RequestObserver {

	private SelectionKey selectKey = null;
	private String clientIp = null;
	private GpcBaseService service = null;
	
	public GpcRequestObserver(String clientIp,SelectionKey selectKey) {
		this.clientIp = clientIp;
		this.selectKey = selectKey;
		this.service = new GpcService();
	}
	
	public void service(GpcRequest request) {
		service.receive(request);
	}
	
	@Override
	public void sendMessage(GpcRequest request) {
		ExecutorServiceTool.execute(new Runnable() {
			
			@Override
			public void run() {
				if(selectKey!=null) {
					ConnectionServer.sendMessage(selectKey, request);
				} else { 
					System.out.println("消息发送失败。客户端："+clientIp+" 异常");
				}
			}
			
		});
	}
	
}
